<template>
  <a-modal v-model:visible.sync="store.state.user.add_status" title="设备信息新增" @ok="handleOk" okText="确认"
           cancelText="取消"
           @cancel="handle_cancel">
    <div class="row_box">
      <div class="column_box">
        <span>设备编号</span>
        <a-input v-model:value="formState.params.equipmentCode" placeholder="请输入数采终端编号"/>
      </div>
      <div class="column_box">
        <span>设备名称</span>
        <a-input v-model:value="formState.params.equipmentName" placeholder="请输入工件名称"/>
      </div>
      <div class="column_box">
        <span>设备型号</span>
        <a-input v-model:value="formState.params.dSortDictId" placeholder="请输入名称"/>
      </div>
      <div class="column_box">
        <span>设备状态</span>
        <a-input v-model:value="formState.params.dStateDictId" placeholder="请输入工件图号"/>
      </div>
      <div class="column_box">
        <span>电压最大设定值</span>
        <a-input v-model:value="formState.params.vMax" placeholder="请输入电压最大设定值"/>
      </div>
      <div class="column_box">
        <span>电压最小设定值</span>
        <a-input v-model:value="formState.params.vMin" placeholder="请输入电压最小设定值"/>
      </div>
      <div class="column_box">
        <span>电流最大设定值</span>
        <a-input v-model:value="formState.params.cMax" placeholder="请输入电流最大设定值"/>
      </div>
      <div class="column_box">
        <span>电流最小设定值</span>
        <a-input v-model:value="formState.params.cMin" placeholder="请输入电流最小设定值"/>
      </div>
      <div class="column_box">
        <span>数采终端编号</span>
        <a-input v-model:value="formState.params.uEquipmentCode" placeholder="请输入数采终端编号"/>
      </div>
    </div>
  </a-modal>
</template>

<script>
import {defineComponent, reactive} from "vue";
import {useStore} from "vuex"
import {editEquipment} from "@/api/device/device"
import {message} from "ant-design-vue";

export default defineComponent({
  name: "add_device",
  setup(props, context) {
    const formState = reactive({
      params: {
        "bId": 0,
        "equipmentCode": "",
        "equipmentName": "",
        "uEquipmentCode": "",
        "collectPoint": "",
        "vMax": 0,
        "vMin": 0,
        "cMax": 0,
        "cMin": 0,
        "tending": "",
        "dSortDictId": 0,
        "dStateDictId": 0,
        "tendingValue": 0,
        "createTime": "",
        "updateTime": "",
        "createUserId": 0,
        "updateUserId": 0
      }
    })

    /**
     * 状态管理
     *
     * */
    const store = useStore()

    /**
     * 确认新增
     *
     * */
    const handleOk = async () => {
      store.commit("SET_ADD_ROLE", false)

      const res = await editEquipment(formState.params)
      console.log(res)
      if (res.code === 1) {
        message.success("新增成功")
        formState.params = {}
        context.emit("re_flash:re_flash", "")
        return
      }
      message.success(res.message)

    }

    /**
     * 取消
     * */
    const handle_cancel = () => {
      store.commit("SET_ADD_ROLE", false)
    }

    return {
      formState,
      //状态管理
      store,
      // methods
      handleOk,
      handle_cancel
    }
  }
})
</script>

<style scoped lang="scss">

</style>
